home *** CD-ROM | disk | FTP | other *** search
/ ...taking it to the Macs! / ...taking it to the Macs!.iso / Extras / ActiveX Mac SDK / ActiveX SDK / Sample Controls / Label / CLabelControl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-20  |  4.2 KB  |  127 lines  |  [TEXT/CWIE]

  1. #ifndef __CLabelControl_h__
  2. #define __CLabelControl_h__
  3.  
  4. #include <QuickDraw.h>
  5. #include <QDOffscreen.h>
  6. #include <fp.h>
  7. #include "CBaseBindStatusCallback.h"
  8.  
  9. class CLabelError;
  10. class CBaseControl;
  11.  
  12.  
  13. ///////////////////////////////////////////////////////////////////////////////
  14. //
  15. //    convenience items
  16. //
  17. #define streq(x,y) (!strcmp((x),(y)))
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. //
  21. // Constants
  22. //
  23.  
  24. // Somewhat arbitrary
  25. const int    MAX_PROPERTY_STRING_LENGTH         = 1023;
  26. const int    MAX_CAPTION_STRING_LENGTH         = 255;
  27. const int    MAX_FONTNAME_LENGTH             = 127;
  28. const short NUM_CONNECTIONS                    = 1;    // This control only has one connection point
  29. const short    twoHundredFiftySixColorsDepth    = 8;
  30. const short    fullRevolution                    = 360;    // full revolution
  31. const short    quarterRevolution                = 90;    // quarter revolution
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. //
  35. // Structs
  36. //
  37.  
  38. typedef struct
  39. {
  40.     Style    textFace;
  41.     short    textFont;
  42.     short    textSize;
  43.     short    textMode;
  44. }
  45. FontParams;
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. //
  49. // CLabelControl class definition
  50. //
  51.  
  52. class CLabelControl : 
  53.     public CBaseControl, 
  54.     public CBaseBindStatusCallback, 
  55.     public CErrorControl
  56. {
  57.  
  58. public:
  59.     // *** construct/destruct methods ***
  60.     CLabelControl();
  61.     ~CLabelControl();
  62.  
  63.     // *** IIUnknown methods ***
  64.     STDMETHOD(QueryInterface)(REFIID inRefID, void** outObj);
  65.     STDMETHOD_(ULONG,AddRef)(THIS) {return CBaseControl::AddRef();}
  66.     STDMETHOD_(ULONG,Release)(THIS) {return CBaseControl::Release();}
  67.  
  68.     // *** IControl methods ***
  69.     STDMETHOD(Draw) (THIS_ DrawContext* Context);
  70.     STDMETHOD(DoMouse)(THIS_ MouseEventType inMouseET, PlatformEvent* inEvent);
  71.  
  72.     //  *** IPersistPropertyBag methods ***
  73.     STDMETHOD(Load)(IPropertyBag* PropBag, IErrorLog* ErrorLog);
  74.     STDMETHOD(LoadTextState)(IPropertyBag *PropertyBag, IErrorLog *ErrorLog);
  75.     
  76.     //    *** Event sending ***
  77.     STDMETHOD(FireEvent)(REFIID RefID, long EventID, PlatformEvent* Event);
  78.     STDMETHOD(FireOneEvent)(REFIID /*RefID*/, long EventID, IUnknown* EventTarget, EventRecord* Event);
  79.     
  80. friend CLabelError;
  81.     
  82. protected:
  83.     void PrepareOffscreenWorld(const DrawContext* Context = nil);
  84.     void MoveOnScreen(const BitMap* offscreenBitMap, const DrawContext* Context = nil);
  85.     void ClearDisplay(void);
  86.     Boolean LoadColor(RGBColor* theColor, char* colorString);
  87.     BitMap* GetOffscreenBitMap(void);
  88.     void ReleaseOffscreenBitMap(BitMap* offscreenBitMap);
  89.  
  90. private:    
  91.     void SetFontParams(GWorldPtr theGWorld);
  92.     void GetTextSize(const StringPtr aString, Point* textSize);
  93.     void RenderLabelControl(void);
  94.     double DegressToRadians(double angDegrees) { return (angDegrees / 180.0) * pi;}
  95.     Point RotatedSize(const double angDegrees, const Point origSize);
  96.     QDErr CreateContent(Point* textSize, GWorldPtr &contentGWorld);
  97.     void ComputeAlignmentRect(Rect &theContentRect, const Rect theLabelRect);
  98.     QDErr Rotate90( const GWorldPtr inputGWorld, GWorldPtr &rotate90GWorld );
  99.     
  100. protected:    // user-defineable parameters
  101.     short            mAngle;                    // caption rotation angle (CCW 0 >= angle >= 360)
  102.     short            mAlignment;                // 0..8 how to align text in control - see property desc
  103.     short            mBackStyle;                // 0..1 background property trans/opaque - see property desc
  104.     RGBColor        mBackColor;                // background color specifier
  105.     char            mCaption[MAX_CAPTION_STRING_LENGTH];// the text in the button
  106.     char            mFontName[MAX_FONTNAME_LENGTH];        // the font name to use for drawing
  107.     Boolean            mFontBold;                // flag for bold
  108.     Boolean            mFontItalic;            // flag for italic
  109.     Boolean            mFontUnderline;            // flag for underline
  110.     Boolean            mFontStrikeout;            // flag for strikeout
  111.     short            mFontSize;                // size of the font in pixels
  112.     RGBColor        mForeColor;                // foreground color specifier
  113.     short            mMode;                    // 0..3 mode text will be rendered in - see property desc
  114.     short            mRotateBy;                // angle to rotate by when clicked
  115.  
  116. private:    // for our use internally:
  117.     FontInfo        mFontInfo;                // fontinfo for the current font
  118.     GWorldPtr        mMainOffscreenGWorld;    // where all the drawing gets done
  119.     PixMapHandle    mPixOffscreenPixMap;    // pixmap of offscreen world
  120.     Rect            mRectOffscreenBounds;    // bounds of offscreen world
  121. };
  122.  
  123. #endif // __CLabelControl_h__
  124.  
  125. // end-of-file
  126.  
  127.